package nku.csc360;

//Raj Akula
import java.io.*;
import java.util.*;

public class HMWK6 {

 	public static void main(String... Args)throws Exception{
 		//Read input
 		BufferedReader input =  new BufferedReader(new FileReader("test.txt"));
 		//Creating Map
 		Map<String, Integer> map = new HashMap<String, Integer>();
 		//String to read line
 		String line;
 		//keeping track of which line
 		@SuppressWarnings("unused")
		int lineNo = 1;
 		int temp;
 		//keeping track of how many words per line
		int wordLength;
		//reading from file.. 
 		line = input.readLine();
 		//reading from file till EOF
		while(line != null){
			//variable for words in file
			String words[];
			//List for all the different line no a string is in... 
			Integer lineNos = 1;
			//initlizing temp
			temp=0;
			//takign line and splitting it into words
			words = line.split(" ");
			//Seeing the no of words per line
			wordLength = words.length;
				do{
					//If word is already in the map then just a line no to the list pair with the word
					if(map.keySet().contains(words[temp])){
						lineNos = map.get(words[temp]);
						lineNos++;
						map.put(words[temp], lineNos);
					}
					//If there is no word then add a new string and and list with that.. 
					else{
						map.put(words[temp],lineNos);
					}
					//this runs till we traversed throught every word in each line
					temp++;
				}while(temp < wordLength);
			// Here reading next line from file
			line = input.readLine();
			//adding a 1 to the lineNo to accurately knw which line we are reading from currently
			lineNo++;
		}

 		@SuppressWarnings("rawtypes")
		Set set = map.keySet();
 		@SuppressWarnings("rawtypes")
		Iterator iterator = set.iterator();
 		while(iterator.hasNext()){
 			String tempString = (String)iterator.next();
 			System.out.println(tempString +" " +map.get(tempString));
 		}
 	}
    
}